home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earkit / news / thor / rexx / uuencode.thor < prev    next >
Text File  |  1998-05-24  |  8KB  |  315 lines

  1. /* UUEncode.thor by Troels Walsted Hansen
  2. ** $VER: UUEncode.thor 2.1 (6.5.96)
  3. **
  4. ** An ARexx script that uuencodes a file and either places it in the
  5. ** clipboard or posts a message for you containing the file. Using
  6. ** LhA, this script will archive the file if it isn't already.
  7. **
  8. ** Utilises LhA by Stefan Boberg for archiving.
  9. ** The script may use either of the following for uuencoding:
  10. **    · UUFast v1.25 by Jørn Halonen
  11. **    · uuIn v1.03 by Nicolas Dade
  12. **    · UUxT v3.0 by Asher Feldman
  13. **
  14. ** New: · Added userdatabase lookup code from ForwardMsg.thor
  15. **        "Post" now works on fido/tcp/uucp/etc. systemtypes.
  16. */
  17.  
  18. /* some user variables. edit to your hearts content */
  19.  
  20. tmpdir = "T:"        /* Work dir for the encoding    */
  21. uuencoder = "uuin"    /* may be: uuin, uufast or uuxt */
  22.  
  23. /* needs THOR and bbsread.library functions */
  24.  
  25. options results
  26. options failat 31
  27.  
  28. p = ' ' || address() || ' ' || show('P',,)
  29. thorport = pos(' THOR.',p)
  30.  
  31. if thorport > 0 then thorport = word(substr(p,thorport+1),1)
  32. else
  33. do
  34.     say 'No THOR port found!'
  35.     exit 10
  36. end
  37.  
  38. if ~show('p', 'BBSREAD') then
  39. do
  40.     address command
  41.         "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  42.         "WaitForPort BBSREAD"
  43. end
  44.  
  45. /* get filename */
  46.  
  47. address(bbsread)
  48. GETGLOBALDATA STEM GLOBALDATA
  49.  
  50. address(thorport)
  51. THORTOFRONT
  52. REQUESTFILE TITLE '"Select file to encode:"' ID '"'GLOBALDATA.UPLOADPATH'"' FP PAT '"#?"'
  53. if(rc ~= 0) then exit
  54.  
  55. filetoencode = result
  56. lastchar = right(filetoencode,1)
  57.  
  58. if(lastchar = "/" | lastchar = ":" | filetoencode = "") then
  59. do
  60.     REQUESTNOTIFY TEXT '"No file selected!"' BT '"_Ok"'
  61.     call CleanUp()
  62. end
  63.  
  64. posi = lastpos("/",FileToEncode)
  65. if(posi = 0) then posi = lastpos(":",FileToEncode)
  66. WithoutPath = substr(FileToEncode,posi+1)
  67.  
  68. /* if file isn't LhA'ed -- do it ourselves */
  69.  
  70. extension = upper(substr(FileToEncode, lastpos(".",FileToEncode)+1))
  71.  
  72. if~(extension = "LHA" | extension = "LZH") then
  73. do
  74.     REQUESTNOTIFY TEXT '"Do you want to LhA the file?"' BT '"_Yes|_No"'
  75.     if(result) then
  76.     do
  77.         address command "LhA >nil: -y -q a "||'"'tmpdir||WithoutPath'"'||" "||'"'FileToEncode'"'
  78.  
  79.         if(rc ~= 0) then REQUESTNOTIFY TEXT '"LhA''ing did not succeed."' BT '"_Ok"'
  80.         else FileToEncode = tmpdir||WithoutPath||".lha"
  81.     end
  82. end
  83.  
  84. /* select correct uuencoder commandstring */
  85.  
  86. select
  87.     when(uuencoder = 'uufast') then cmd = "UUFast >nil: " || '"' || filetoencode || '"' || " TO " || tmpdir || "Message.uu E"
  88.     when(uuencoder = 'uuin') then cmd = "uuIn >nil: INFILE=" || '"' || filetoencode || '"' || " OUTFILE=" || tmpdir || "Message.uu"
  89.     when(uuencoder = 'uuxt') then cmd = 'UUxT >nil: a ' || tmpdir || 'Message.uu ' || '"'filetoencode'"'
  90.     otherwise
  91.     do
  92.         REQUESTNOTIFY TEXT '"UUEncoder not configured correctly."' BT '"_Ok"'
  93.         call CleanUp()
  94.     end
  95. end
  96. address command cmd
  97.  
  98. if ~exists(tmpdir"Message.uu") then
  99. do
  100.     REQUESTNOTIFY TEXT '"Something went wrong during uuencoding."' BT '"_Ok"'
  101.     call CleanUp()
  102. end
  103.  
  104. REQUESTNOTIFY TEXT '"Place in clipboard or post as a message?"' BT '"Clip_board|_Post|_Cancel"'
  105. choice = result
  106.  
  107. if(choice = 1) then
  108. do
  109.     PUTCLIP unit 0 file '"'tmpdir'Message.uu"'
  110.     if(rc ~= 0) then
  111.     do
  112.         address(thorport)
  113.         REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
  114.         exit 5
  115.     end
  116. end
  117. else if(choice = 2) then
  118. do
  119.     drop EVENT.
  120.     address(bbsread)
  121.  
  122.     GETBBSLIST stem BBSLIST
  123.     if(rc ~= 0) then
  124.     do
  125.         address(thorport)
  126.         REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  127.         exit 5
  128.     end
  129.  
  130.     address(thorport)
  131.  
  132.     REQUESTLIST instem BBSLIST title '"Select BBS:"' SIZEGADGET
  133.     if(rc ~= 0) then break
  134.     else bbs = result
  135.  
  136.     address(bbsread)
  137.         GETCONFLIST '"'bbs'"' CONFLIST
  138.     if(rc ~= 0) then
  139.     do
  140.         address(thorport)
  141.         REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  142.         exit 5
  143.     end
  144.  
  145.     address(thorport)
  146.  
  147.     REQUESTLIST instem CONFLIST title '"Select conf:"' SIZEGADGET
  148.     if(rc ~= 0) then break
  149.     else EVENT.CONFERENCE = result
  150.  
  151.     REQUESTSTRING TITLE '"Please enter subject of message:"' BT '"_Ok|_Cancel"' ID '"'WithoutPath'"' MAXCHARS 100
  152.     EVENT.SUBJECT = result
  153.     if(rc ~= 0 | EVENT.SUBJECT = "") then break
  154.  
  155.     do forever
  156.         REQUESTSTRING TITLE '"Please enter receiver name:"' BT '" _Ok | _Cancel "' MAXCHARS 200
  157.         if(rc ~= 0) then exit
  158.         forwardto = result
  159.  
  160.  
  161.         if(upper(forwardto) ~= "ALL") then
  162.         do
  163.             address(bbsread)
  164.  
  165.             /*
  166.                 The message was not addressed to 'ALL',
  167.                 let's search for the user on the system
  168.                 the message is to be forwarded to.
  169.                 Both name, addresses and aliases will be searched
  170.                 for to find a match.
  171.             */
  172.  
  173.             SEARCHBRUSER bbsname '"'bbs'"' stem USERS search '"'forwardto'"' name address alias suggestusersstem SUG
  174.             if(rc ~= 0) then goto quit
  175.  
  176.             if(result > 0) then
  177.             do
  178.                 /* Ok, we found one or more users matching the data entered exactly */
  179.  
  180.                 address(bbsread)
  181.  
  182.                 drop LIST.
  183.                 drop USERTAGS.
  184.  
  185.                 LIST.COUNT = USERS.COUNT
  186.  
  187.                 /*
  188.                     We must build a list of user names suitable to
  189.                     be viewed with the REQUESTLIST command.
  190.                 */
  191.  
  192.                 do n = 1 to USERS.COUNT
  193.                     LIST.n.USERNR = USERS.n.USERNR
  194.                     READBRUSER bbsname '"'bbs'"' usernr USERS.n.USERNR tagsstem USERTAGS
  195.                     if(rc ~= 0) then goto quit
  196.                     LIST.n = USERTAGS.NAME
  197.  
  198.                     if(symbol("USERTAGS.ADDRESS") = "VAR") then
  199.                         LIST.n.ADDRESS = USERTAGS.ADDRESS
  200.                 end
  201.  
  202.                 /* Select a user */
  203.  
  204.                 address(thorport)
  205.                 REQUESTLIST instem LIST title '"Select user:"'
  206.                 if(rc ~= 0) then
  207.                 do
  208.                     if(rc ~= 5) then REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
  209.                     exit
  210.                 end
  211.  
  212.                 forwardto = result
  213.  
  214.                 /* We might have an address (email address/Fido address etc.) */
  215.  
  216.                 do n = 1 to LIST.COUNT
  217.                     if(LIST.n = forwardto) then
  218.                         forwardaddress = LIST.n.ADDRESS
  219.                 end
  220.                 leave
  221.             end
  222.             else
  223.             do
  224.                 /*
  225.                     No users matching the given data exactly were found,
  226.                     let's prosess the suggestions.
  227.                 */
  228.  
  229.                 if(symbol("SUG.COUNT") = "VAR") then do
  230.                     address(thorport)
  231.                     REQUESTLIST instem SUG title '"Select user:"'
  232.                     if(rc ~= 0) then
  233.                     do
  234.                         if(rc ~= 5) then REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
  235.                         exit
  236.                     end
  237.  
  238.                     forwardto = result
  239.  
  240.                     /* Let's find the user number of the user selected */
  241.  
  242.                     do n = 1 to SUG.COUNT
  243.                         if(SUG.n = forwardto) then
  244.                             usernumber = SUG.n.USERNR
  245.                     end
  246.  
  247.                     drop USERTAGS.
  248.  
  249.                     address(bbsread)
  250.  
  251.                     /* Get some data about the user selected */
  252.  
  253.                     READBRUSER bbsname '"'bbs'"' usernr usernumber tagsstem USERTAGS
  254.                     if(rc ~= 0) then goto quit
  255.  
  256.                     if(symbol("USERTAGS.ADDRESS") = "VAR") then
  257.                         forwardaddress = USERTAGS.ADDRESS
  258.  
  259.                     leave
  260.                 end
  261.                 else
  262.                 do
  263.                     /* No users were found in the search */
  264.  
  265.                     address(thorport)
  266.                     REQUESTNOTIFY TEXT '"No matching users found, try again?"' BT '"_Ok | _Cancel"'
  267.                     if(rc ~= 0) then exit
  268.                     if(result = 0) then exit
  269.                 end
  270.             end
  271.         end
  272.         else
  273.             leave
  274.     end
  275.  
  276.     EVENT.TONAME = forwardto
  277.     EVENT.TOADDR = forwardaddress
  278.  
  279.     address(bbsread)
  280.     UNIQUEMSGFILE bbsname '"'bbs'"' stem UNIQUEFILE
  281.     if(rc ~= 0) then
  282.     do
  283.         address(thorport)
  284.         REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  285.         exit
  286.     end
  287.  
  288.     address command 'copy >nil: ' || tmpdir || 'Message.uu TO ' || UNIQUEFILE.NAME
  289.     EVENT.MSGFILE = UNIQUEFILE.FILEPART
  290.  
  291.     WRITEBREVENT bbsname '"'bbs'"' event 0 stem EVENT
  292.     if(rc ~= 0) then
  293.     do
  294.         address(thorport)
  295.         REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  296.         exit 5
  297.     end
  298.     else
  299.     do
  300.         address(thorport)
  301.         PACKEVENTS '"'bbs'"'
  302.         RESCAN
  303.     end
  304. end
  305.  
  306. call CleanUp()
  307.  
  308. /* cleanup and exit */
  309.  
  310. CleanUp:
  311.     if(exists(tmpdir || WithoutPath || ".lha")) then address command 'delete >nil: ' || '"' || tmpdir || WithoutPath || '.lha' || '"'
  312.     if(exists(tmpdir || "Message.uu")) then address command 'delete >nil: ' || tmpdir || 'Message.uu'
  313.     exit
  314. return
  315.